package com.fitso.model.bean;

import java.io.Serializable;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

public class Phone extends ModelBean implements Comparable<Phone>, Serializable {
	// Only change on breaking changes, i.e., removing fields
	private static final long serialVersionUID = 1;
	
	private Integer _area; /* 719 */
	private Integer _country; /* 001 */
	private Integer _number; /* 5551234 */

	public Phone() {}

	public Phone(Integer area, Integer number) {
		_area = area;
		_number = number;
	}

	public Phone(Integer country, Integer area, Integer number) {
		_country = country;
		_area = area;
		_number = number;
	}

	public boolean equals(Object o) {
		if (o == null) {
			return false;
		}
		if (o == this) {
			return true;
		}
		if (o.getClass() != getClass()) {
			return false;
		}

		Phone other = (Phone) o;
		return new EqualsBuilder().append(_area, other._area).append(_number, other._number).isEquals();
	}

	public Integer getArea() {
		return _area;
	}

	public Integer getCountry() {
		return _country;
	}

	public Integer getNumber() {
		return _number;
	}

	public int hashCode() {
		return new HashCodeBuilder().append(_area).append(_number).toHashCode();
	}

	public void setArea(Integer area) {
		_area = area;
	}

	public void setCountry(Integer country) {
		_country = country;
	}

	public void setNumber(Integer number) {
		_number = number;
	}

	public String toString() {
		if (_country == null) {
			return String.format("(%d)%s-%s", _area, _number.toString().substring(0, 3), _number.toString()
					.substring(3));
		}
		return String.format("+%d (%d)%s-%s", _country, _area, _number.toString().substring(0, 3), _number.toString()
				.substring(3));
	}

	public int compareTo(Phone other) {
		return new CompareToBuilder().append(_country, other._country).append(_area, other._area).append(_number,
				other._number).toComparison();
	}
}
